﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text.RegularExpressions;
using Imgalib.Utility;

namespace NRCP.Helpers
{
    public class SiteUtility
    {
        public static Int32 IntQueryParam
        {
            get
            {
                try
                {
                    if (HttpContext.Current.Request.QueryString != null && !string.IsNullOrEmpty(HttpContext.Current.Request.QueryString["params"]))
                    {
                        return Convert.ToInt32(Cryptography.Decrypt(HttpContext.Current.Request.QueryString["params"].ToString()));
                    }
                    else
                    {
                        return -1;
                    }
                }
                catch
                {
                    return -1;
                }
            }
        }

        public static string LitQueryParam
        {
            get
            {
                try
                {
                    if (HttpContext.Current.Request.QueryString != null && !string.IsNullOrEmpty(HttpContext.Current.Request.QueryString["params"]))
                    {
                        return Cryptography.Decrypt(HttpContext.Current.Request.QueryString["params"].ToString());
                    }
                    else
                    {
                        return string.Empty;
                    }
                }
                catch
                {
                    return string.Empty;
                }
            }
        }

        public static string QueryParam
        {
            get
            {
                try
                {
                    if (HttpContext.Current.Request.QueryString != null && !string.IsNullOrEmpty(HttpContext.Current.Request.QueryString["params"]))
                    {
                        return HttpContext.Current.Request.QueryString["params"].ToString();
                    }
                    else
                    {
                        return string.Empty;
                    }
                }
                catch
                {
                    return string.Empty;
                }
            }
        }

        private Boolean IsEmail(String stringToMatch)
        {
            return Regex.IsMatch(stringToMatch, @"^[a-z A-Z 0-9 \s]+$", RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace | RegexOptions.Multiline | RegexOptions.CultureInvariant);
        }

        public static string GetQueryParameter(string param)
        {
            try
            {
                if (HttpContext.Current.Request.QueryString != null && !string.IsNullOrEmpty(HttpContext.Current.Request.QueryString[param]))
                {
                    return HttpContext.Current.Request.QueryString[param].ToString();
                }
                else
                {
                    return null;
                }
            }
            catch
            {
                return null;
            }
        }
    }
}